<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.sales.LineItem,
                 com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.sales.forms.SalesOrderForm,
                 java.util.ArrayList,
                 org.apache.struts.util.LabelValueBean,
                 java.util.HashMap,
                 com.scalar.chiptrack.sales.SalesOrder"%>
<table border="0" width="100%" >
	 <tr>
	   <td width="8%" align="center" bgcolor="#993333" class="NArialL">
            <font color="#FFFFFF">Line Item</font></td>
       <td width="8%" align="center" bgcolor="#993333" class="NArialL">
            <font color="#FFFFFF">PO Line Item</font></td>
	   <td width="18%" align="center" bgcolor="#993333" class="NArialL">
	        <font color="#FFFFFF"><bean:message key="label.mfgPartNumber" />&nbsp;*</font>
       </td>
       <td width="10%" align="center" bgcolor="#993333" class="NArialL">
            <font color="#FFFFFF"><bean:message key="label.customerPartNumber"/></font>
		</td>
           <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){ %>
           <td width="10%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">
				<bean:message key="label.labelNumber"/>
				</font></td>
           <%}%>
           <td width="10%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">Description</font></td>
	   <td width="5%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">Quantity</font></td>
	   <td width="8%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">Price </font></td>
	   <td width="8%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">Amount</font></td>
           <td width="8%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">Req'd Dock Date</font></td>
           <td width="12%" align="center" bgcolor="#993333" class="NArialL">
                <font color="#FFFFFF">Schedule Date</font></td>
           <td width="20%" bgcolor='#993333'>
            <table width="100%" border=0>
                <tr><td colspan=4 class="NArialL" align=center><font color="#FFFFFF">Holds</font></td></tr>
                <font size="-3"><tR><td width="25%" align=left class="NArialL"><font color="#FFFFFF">Mktg</font></td><td  width="25%" align=center class="NArialL"><font color="#FFFFFF">Fin</font></td><td width="25%" align=right class="NArialL"><font color="#FFFFFF">Ops</FONT></td><td  align=right width="25%" class="NArialL"><font color="#FFFFFF">&nbsp;&nbsp;&nbsp;Sales</FONT></td></tr></font>
            </table>
           </td>
        <%
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_PRICE_FIELD1)) {
         %>
            <td width="8%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.lineItem.customPriceField1" /></font></td>
         <%
             }
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_TEXT_FIELD1)) {
         %>
                <td width="8%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.lineItem.customTextField1" /></font></td>
         <%
             }
         %>
         </tr>
        <!-- logic iterate previous line items -->
<%
    HashMap  salesOrderMap = ( HashMap ) session.getAttribute( "salesOrderMap" );
    ArrayList previousLineItems = null;
    if ( salesOrderMap != null ) {
      com.scalar.chiptrack.sales.forms.SalesOrderForm salesOrderForm1 = (SalesOrderForm)request.getAttribute("salesOrderForm");
      SalesOrder salesOrderFromMap = (SalesOrder)( salesOrderMap.get( salesOrderForm1.getCustomerId()+"" ));
      previousLineItems = salesOrderFromMap.getPreviousLineItems();
    }

    for(int j=0;j<previousLineItems.size();j++)
    {
        LineItem lineItem = (LineItem) previousLineItems.get(j);
%>
       <tr>
	   <td width="8%" bgcolor="#DEE1E2">
                <font class="NArialL"><%=lineItem.getLineItemNo()%></font></td>
       <td width="8%" bgcolor="#DEE1E2">
                <%
                    if(lineItem.getPoLineItemNo()==0)
                    {
                        out.println("<font class='NArialL'>&nbsp;</font>");
                    }
                    else
                    {
                        out.println("<font class='NArialL'>"+lineItem.getPoLineItemNo()+"</font>");
                    }
                %>
        </td>
        <td  bgcolor="#DEE1E2">
             <font class="NArialL"><%=lineItem.getManufacturingPartNo()%></font></td>

        <td width="10%" bgcolor="#DEE1E2">
             <font class="NArialL"><%=(lineItem.getCustomerPartNo()==null?"":lineItem.getCustomerPartNo())%></font></td>
          <%if(Constants.CLIENT_NAME_AIRGO.equalsIgnoreCase(ConfigManager.getClientNameAirgo() )){ %>
        <td width="10%" bgcolor="#DEE1E2">
              <font class="NArialL"><%=(lineItem.getLabelNumber()==null?"":lineItem.getLabelNumber())%></font></td>
            <%}%>
         <td width="10%" bgcolor="#DEE1E2">
                <font class="NArialL"><%=lineItem.getLineItemDescription()%></font> </td>
         <td width="5%" bgcolor="#DEE1E2" align=right>
                <font class="NArialL"><%=lineItem.getQtyAsString()%></font></td>
           <td width="8%" bgcolor="#DEE1E2" align=right>
                <font class="NArialL"><%=lineItem.getUnitPriceAsString()%></font></td>
           <td width="8%" bgcolor="#DEE1E2" align=right>
                <font class="NArialL"><%=lineItem.getAmountAsString()%></font></td>
           <td width="8%" bgcolor="#DEE1E2">
                <font class="NArialL"><%=lineItem.getRequestDate()%></font></td>
           <td width="12%" bgcolor="#DEE1E2">
                <font class="NArialL"><%=lineItem.getScheduleDate()%></font></td>
           <td width="20%" bgcolor="#DEE1E2">
                <table with="100%">
                <tr>
                    <td class="NArialL">
                        <select name="marketingHold" class="txfield" disabled="true">
                            <option value=""></option>
                                <%
                                    if(lineItem.getMarketingHold().equals("0"))
                                    {
                                %>
                                    <option value="0" SELECTED>X</option>
                                <%
                                    }
                                    else
                                    {

                                %>
                                    <option value="0">X</option>
                                <%
                                    }
                                %>
                                <%
                                    ArrayList marketingReasonCodes = (ArrayList) request.getAttribute("marketingReasonCodes");

                                    for(int k=0;k<marketingReasonCodes.size();k++)
                                    {
                                        LabelValueBean lb = (LabelValueBean)marketingReasonCodes.get(k);

                                        if(lineItem.getMarketingHold().equals(lb.getValue()))
                                        {
                                %>
                                        <option value=<%=lb.getValue()%> SELECTED><%=lb.getValue()%></option>
                                    <%
                                        }
                                        else
                                        {
                                    %>
                                        <option value=<%=lb.getValue()%> ><%=lb.getValue()%></option>
                                <%
                                        }
                                    }
                                %>
                        </select>
                        </td>
                    <td class="NArialL">
                        <select name="financeHold" class="txfield" disabled="true">
                            <option value=""></option>
                                <%
                                    if(lineItem.getFinanceHold().equals("0"))
                                    {
                                %>
                                    <option value="0" SELECTED>X</option>
                                <%
                                    }
                                    else
                                    {
                                %>
                                    <option value="0">X</option>
                                <%
                                    }
                                %>
                                <%
                                    ArrayList financeReasonCodes = (ArrayList) request.getAttribute("financeReasonCodes");

                                    for(int k=0;k<financeReasonCodes.size();k++)
                                    {
                                        LabelValueBean lb = (LabelValueBean)financeReasonCodes.get(k);

                                        if(lineItem.getFinanceHold().equals(lb.getValue()))
                                        {
                                %>
                                        <option value=<%=lb.getValue()%> SELECTED><%=lb.getValue()%></option>
                                    <%
                                        }
                                        else
                                        {
                                    %>
                                        <option value=<%=lb.getValue()%> ><%=lb.getValue()%></option>
                                <%
                                        }
                                    }
                                %>
                        </select>
                        </td>
                    <td class="NArialL">
                        <select name="operationsHold" class="txfield" disabled="true">
                            <option value=""></option>
                                <%
                                    if(lineItem.getOperationsHold().equals("0"))
                                    {
                                %>
                                    <option value="0" SELECTED>X</option>
                                <%
                                    }
                                    else
                                    {
                                %>
                                    <option value="0">X</option>
                                <%
                                    }
                                %>
                                <%
                                    ArrayList operationsReasonCodes = (ArrayList) request.getAttribute("opsReasonCodes");

                                    for(int k=0;k<operationsReasonCodes.size();k++)
                                    {
                                        LabelValueBean lb = (LabelValueBean)operationsReasonCodes.get(k);
                                        if(lineItem.getOperationsHold().equals(lb.getValue()))
                                        {
                                %>
                                        <option value=<%=lb.getValue()%> SELECTED><%=lb.getValue()%></option>
                                    <%
                                        }
                                        else
                                        {
                                    %>
                                        <option value=<%=lb.getValue()%> ><%=lb.getValue()%></option>
                                <%
                                        }
                                    }
                                %>
                        </select>
                        </td>
                    <td class="NArialL">
                        <select name="salesHold" class="txfield" disabled="true">
                            <option value=""></option>
                                <%
                                    if(lineItem.getSalesHold().equals("0"))
                                    {
                                %>
                                    <option value="0" SELECTED>X</option>
                                <%
                                    }
                                    else
                                    {
                                %>
                                    <option value="0">X</option>
                                <%
                                    }
                                %>
                                <%
                                    ArrayList salesReasonCodes = (ArrayList) request.getAttribute("salesReasonCodes");

                                    for(int k=0;k<salesReasonCodes.size();k++)
                                    {
                                        LabelValueBean lb = (LabelValueBean)salesReasonCodes.get(k);

                                        if(lineItem.getSalesHold().equals(lb.getValue()))
                                        {
                                %>
                                        <option value=<%=lb.getValue()%> SELECTED><%=lb.getValue()%></option>
                                    <%
                                        }
                                        else
                                        {
                                    %>
                                        <option value=<%=lb.getValue()%> ><%=lb.getValue()%></option>
                                <%
                                        }
                                    }
                                %>
                        </select>
                        </td>
                </tr>
             </table>
           </td>
            <%
                 if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_PRICE_FIELD1)) {
             %>
                <td width="8%" bgcolor="#DEE1E2" align=right>
                    <font class="NArialL"><%=lineItem.getCustomPriceField1AsString()%></font></td>
             <%
                 }
                 if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_TEXT_FIELD1)) {
             %>
                <td width="8%" bgcolor="#DEE1E2">
                    <font class="NArialL"><%=lineItem.getCustomTextField1()==null?"":lineItem.getCustomTextField1()%></font></td>
             <%
                 }
             %>
         </tr>
<%
    }
%>
        <!-- logic iterate previous line items -->
</table>
